import { readable, writable, derived } from 'svelte/store';
import { dispatch } from "$lib/tauri";

let data = undefined;
export const actixGraphqlEndpoint = readable(data, makeSubscribe(data, ""));

// current recall difficulty
export const activeFolderId = writable<string>();

function unsubscribe() {
  // Nothing to do in this case
}

function makeSubscribe(data, _args) {
  // 2. Create a closure with access to the 
  // initial data and initialization arguments
  return set => {
    // 3. This won't get executed until the store has 
    // its first subscriber. Kick off retrieval.
    fetchGqlEndpointData(data, set);

    // 4. We're not waiting for the response.
    // Return the unsubscribe function which doesn't do
    // do anything here (but is part of the stores protocol).
    return unsubscribe;
  };
}

async function fetchGqlEndpointData(data, set) {
  const response = await dispatch("get_actix_graphql_endpoint");

  console.log("fetchGqlEndpointData response=",response);

  set(response);
}

